package container
{
	import camo.core.decal.DecalSheet;
	
	import com.adobe.serialization.json.JSON;
	
	import components.ColorHSB;
	import components.Combobox;
	import components.DecalDisplay;
	import components.Label;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.net.URLLoader;
	import flash.net.URLLoaderDataFormat;
	import flash.net.URLRequest;
	import flash.net.URLRequestMethod;
	import flash.text.TextFormat;
	
	import managers.GlobalDecalSheetManager;
		
	public class WindowSelectAuto extends Sprite
	{	
		private var boxButtonClose:				DecalDisplay;
		private var boxColorSelect:				DecalDisplay;
		private var boxSaturationSelect:		DecalDisplay;
		private var boxBrightnessSelect:		DecalDisplay;
		private var boxSliderColorSelect:		DecalDisplay;
		private var boxSliderSaturationSelect:	DecalDisplay;
		private var boxSliderBrightnessSelect:	DecalDisplay;
		
		private var saturationBorder:			Bitmap;
		private var brightnessBorder:			Bitmap;
		
		private var boxButtonParameters:		DecalDisplay;
		private var boxButtonFitting:			DecalDisplay;
		
		private var boxAuto: 					DecalDisplay;
		
		private var currentBoxSlider: 			DecalDisplay;
		
		private var curHSB:ColorHSB  = new ColorHSB(359, 100, 100);
		
		private var AutoSourceBMD:				BitmapData;
		private var AutoBM:						Bitmap;
		private var rectAuto:					Rectangle;
		
		private var comboboxMark:					Combobox;
		private var comboboxYears:					Combobox;
		private var comboboxModel:					Combobox;
		private var comboboxVersion:				Combobox;		
		
		private var Boxes: Array = new Array("Box-SelectAuto_Window");
		private var Labels: Array = new Array("Label-SelectAuto_Title",
									"Label-SelectAuto_Mark",
									"Label-SelectAuto_Years",
									"Label-SelectAuto_Model",
									"Label-SelectAuto_Version",
									"Label-SelectAuto_Color",
									"Label-SelectAuto_Saturation",
									"Label-SelectAuto_Brightness");
		
		public static const DecalNameOver:String = "Over";
		private const DecalNameDown:String = "Down";
		
		public function WindowSelectAuto(brendXml:XMLList, urlXml:XML){
			visible = false;
			constractOverButtonSheet();
			addComponents(Boxes, Labels, brendXml, urlXml);
			auto();
			visible = true;
		}
		
		private function constractOverButtonSheet():void{
			var buttonsOver: DecalSheet = GlobalDecalSheetManager.instance.getSheet("ButtonWindowSelectAuto");
			for (var key:Object in buttonsOver.decalRectangles){
				GlobalDecalSheetManager.instance.newDecal(key+DecalNameOver,"ButtonOverWindowSelectAuto",
					buttonsOver.decalRectangles[key].x,	buttonsOver.decalRectangles[key].y,
					buttonsOver.decalRectangles[key].width,buttonsOver.decalRectangles[key].height);
				GlobalDecalSheetManager.instance.newDecal(key+DecalNameDown,"ButtonDownWindowSelectAuto",
					buttonsOver.decalRectangles[key].x,	buttonsOver.decalRectangles[key].y,
					buttonsOver.decalRectangles[key].width,buttonsOver.decalRectangles[key].height);
			}
			//trace(GlobalDecalSheetManager.instance.getSheet("ButtonOverWindowSelectAuto").decalNames);
		}
		
		private function addComponents(boxComponents: Array, labelComponents: Array, brendXml:XMLList, urlXml:XML):void{
			
			var yearsValue:Vector.<String>;
			var modelValue:Vector.<String>;
			var versionValue:Vector.<String>;
			
			for (var i:int = 0; i < boxComponents.length; i++){
				var TempDecal: DecalDisplay = new DecalDisplay(boxComponents[i]);
				addChild(TempDecal);
			}
			
			boxButtonClose = new DecalDisplay("Box-SelectAuto_ButtonClose");
			addChild(boxButtonClose);
			boxButtonClose.buttonMode = true;
			boxButtonClose.addEventListener(MouseEvent.MOUSE_OVER, ButtonOver);
			
			boxColorSelect = new DecalDisplay("Box-SelectAuto_ColorSelect");
			addChild(boxColorSelect);
			var hueBar:Bitmap = new Bitmap(new BitmapData(boxColorSelect.width, boxColorSelect.height));
			boxColorSelect.addChild(hueBar);
			change_rcx1_hsb(curHSB, hueBar, 0);
			boxSliderColorSelect= new DecalDisplay("Box-SelectAuto_SliderColorSelect");
			boxSliderColorSelect.x = - boxSliderColorSelect.width / 2;
			boxSliderColorSelect.y -= boxSliderColorSelect.height / 2;
			boxColorSelect.addChild(boxSliderColorSelect);
			boxColorSelect.buttonMode = true;
			boxSliderColorSelect.addEventListener(MouseEvent.MOUSE_OVER, ButtonOver);
			boxSliderColorSelect.addEventListener(MouseEvent.MOUSE_DOWN, SliderDown);
			boxColorSelect.addEventListener(MouseEvent.MOUSE_DOWN, boxSliderDown);
			
			boxSaturationSelect= new DecalDisplay("Box-SelectAuto_SaturationSelect");
			saturationBorder = new Bitmap(new BitmapData(boxSaturationSelect.width + 2, boxSaturationSelect.height + 2,
												true, ColorHSB.hsb_to_rgb(new ColorHSB(curHSB.h, 50, curHSB.b))|0xFF000000));
			saturationBorder.x = boxSaturationSelect.x - 1;
			saturationBorder.y = boxSaturationSelect.y - 1;
			addChild(saturationBorder);
			addChild(boxSaturationSelect);
			var saturationBar:Bitmap = new Bitmap(new BitmapData(boxSaturationSelect.width, boxSaturationSelect.height));
			boxSaturationSelect.addChild(saturationBar);
			change_rcx1_hsb(curHSB, saturationBar, 1);
			boxSliderSaturationSelect= new DecalDisplay("Box-SelectAuto_SliderSaturationSelect");
			boxSliderSaturationSelect.x = - boxSliderSaturationSelect.width / 2;
			boxSliderSaturationSelect.y -= boxSliderSaturationSelect.height / 2;
			boxSaturationSelect.addChild(boxSliderSaturationSelect);
			boxSaturationSelect.buttonMode = true;
			boxSliderSaturationSelect.addEventListener(MouseEvent.MOUSE_OVER, ButtonOver);
			boxSliderSaturationSelect.addEventListener(MouseEvent.MOUSE_DOWN, SliderDown);
			boxSaturationSelect.addEventListener(MouseEvent.MOUSE_DOWN, boxSliderDown); 
			
			boxBrightnessSelect= new DecalDisplay("Box-SelectAuto_BrightnessSelect");
			brightnessBorder = new Bitmap(new BitmapData(boxBrightnessSelect.width + 2, boxBrightnessSelect.height + 2,
												true, ColorHSB.hsb_to_rgb(new ColorHSB(curHSB.h, 50, 50))|0xFF000000));
			brightnessBorder.x = boxBrightnessSelect.x - 1;
			brightnessBorder.y = boxBrightnessSelect.y - 1;
			addChild(brightnessBorder);
			addChild(boxBrightnessSelect);
			var brightnessBar:Bitmap = new Bitmap(new BitmapData(boxBrightnessSelect.width, boxBrightnessSelect.height));
			boxBrightnessSelect.addChild(brightnessBar);
			change_rcx1_hsb(curHSB, brightnessBar, 2);
			boxSliderBrightnessSelect= new DecalDisplay("Box-SelectAuto_SliderBrightnessSelect");
			boxSliderBrightnessSelect.x = - boxSliderBrightnessSelect.width / 2;
			boxSliderBrightnessSelect.y -= boxSliderBrightnessSelect.height / 2;
			boxBrightnessSelect.addChild(boxSliderBrightnessSelect);
			boxBrightnessSelect.buttonMode = true;
			boxSliderBrightnessSelect.addEventListener(MouseEvent.MOUSE_OVER, ButtonOver);
			boxSliderBrightnessSelect.addEventListener(MouseEvent.MOUSE_DOWN, SliderDown);
			boxBrightnessSelect.addEventListener(MouseEvent.MOUSE_DOWN, boxSliderDown);
			
			boxButtonParameters = new DecalDisplay("Box-SelectAuto_ButtonParameters");
			addChild(boxButtonParameters);
			boxButtonParameters.buttonMode = true;
			boxButtonParameters.addEventListener(MouseEvent.MOUSE_OVER, ButtonOver);
			boxButtonParameters.addEventListener(MouseEvent.MOUSE_DOWN, ButtonDown);
			
			boxButtonFitting = new DecalDisplay("Box-SelectAuto_ButtonFitting");
			addChild(boxButtonFitting);
			boxButtonFitting.buttonMode = true;
			boxButtonFitting.addEventListener(MouseEvent.MOUSE_OVER, ButtonOver);
			boxButtonFitting.addEventListener(MouseEvent.MOUSE_DOWN, ButtonDown);
			
			for (var j:int = 0; j < labelComponents.length; j++){
				var TempLabel: Label = new Label(labelComponents[j]);
				addChild(TempLabel);
			}
			
			var listMarkLabel:Label = new Label("Label-SelectAuto_MarkComboBoxList");
			var textMarkFormatList:TextFormat =  new TextFormat(listMarkLabel.font, listMarkLabel.size, listMarkLabel.color, listMarkLabel.bold, listMarkLabel.italic);
			var locationMarkTextOnList:Point = new Point(listMarkLabel.x, listMarkLabel.y);
			
			var comboMarkLabel:Label = new Label("Label-SelectAuto_MarkComboBox");
			var textMarkFormatCombo:TextFormat =  new TextFormat(comboMarkLabel.font, comboMarkLabel.size, comboMarkLabel.color, comboMarkLabel.bold, comboMarkLabel.italic);
			var locationMarkTextOnCombo:Point = new Point(comboMarkLabel.x, comboMarkLabel.y);
			comboboxMark = new Combobox("Box-SelectAuto_MarkComboBox", "Box-SelectAuto_MarkComboBoxScroll",
				"Box-SelectAuto_MarkComboBoxSelectSkin", "Box-SelectAuto_MarkComboBoxSlider", "Box-SelectAuto_MarkComboBoxListBackground",
				textMarkFormatList, listMarkLabel.embedFonts, locationMarkTextOnList, textMarkFormatCombo, comboMarkLabel.embedFonts, locationMarkTextOnCombo, comboMarkLabel.text);
			addChild(comboboxMark);
			var brendArray:Vector.<String> = new Vector.<String>();
			brendArray.length = brendXml.length();
			brendArray.fixed = true;
			for (var i1:int = 0; i1 < brendArray.length; i1++){brendArray[i1] = brendXml[i1]}
			comboboxMark.list.Data = brendArray;
			comboboxMark.addEventListener("changeCombobox", updateNextList);
			
			var listYearsLabel:Label = new Label("Label-SelectAuto_YearsComboBoxList");
			var textYearsFormatList:TextFormat =  new TextFormat(listYearsLabel.font, listYearsLabel.size, listYearsLabel.color, listYearsLabel.bold, listYearsLabel.italic);
			var locationYearsTextOnList:Point = new Point(listYearsLabel.x, listYearsLabel.y);
			
			var comboYearsLabel:Label = new Label("Label-SelectAuto_YearsComboBox");
			var textYearsFormatCombo:TextFormat =  new TextFormat(comboYearsLabel.font, comboYearsLabel.size, comboYearsLabel.color, comboYearsLabel.bold, comboYearsLabel.italic);
			var locationYearsTextOnCombo:Point = new Point(comboYearsLabel.x, comboYearsLabel.y);
			comboboxYears = new Combobox("Box-SelectAuto_YearsComboBox", "Box-SelectAuto_YearsComboBoxScroll",
				"Box-SelectAuto_YearsComboBoxSelectSkin", "Box-SelectAuto_YearsComboBoxSlider", "Box-SelectAuto_YearsComboBoxListBackground",
				textYearsFormatList, listYearsLabel.embedFonts, locationYearsTextOnList, textYearsFormatCombo, comboYearsLabel.embedFonts, locationYearsTextOnCombo, comboYearsLabel.text);
			addChild(comboboxYears);
			comboboxYears.addEventListener("changeCombobox", updateNextList);
			
			var listModelLabel:Label = new Label("Label-SelectAuto_ModelComboBoxList");
			var textModelFormatList:TextFormat =  new TextFormat(listModelLabel.font, listModelLabel.size, listModelLabel.color, listModelLabel.bold, listModelLabel.italic);
			var locationModelTextOnList:Point = new Point(listModelLabel.x, listModelLabel.y);
			
			var comboModelLabel:Label = new Label("Label-SelectAuto_ModelComboBox");
			var textModelFormatCombo:TextFormat =  new TextFormat(comboModelLabel.font, comboModelLabel.size, comboModelLabel.color, comboModelLabel.bold, comboModelLabel.italic);
			var locationModelTextOnCombo:Point = new Point(comboModelLabel.x, comboModelLabel.y);
			comboboxModel = new Combobox("Box-SelectAuto_ModelComboBox", "Box-SelectAuto_ModelComboBoxScroll",
				"Box-SelectAuto_ModelComboBoxSelectSkin", "Box-SelectAuto_ModelComboBoxSlider", "Box-SelectAuto_ModelComboBoxListBackground",
				textModelFormatList, listModelLabel.embedFonts, locationModelTextOnList, textModelFormatCombo, comboModelLabel.embedFonts, locationModelTextOnCombo, comboModelLabel.text);
			addChild(comboboxModel);
			comboboxModel.addEventListener("changeCombobox", updateNextList);
			
			var listVersionLabel:Label = new Label("Label-SelectAuto_VersionComboBoxList");
			var textVersionFormatList:TextFormat =  new TextFormat(listVersionLabel.font, listVersionLabel.size, listVersionLabel.color, listVersionLabel.bold, listVersionLabel.italic);
			var locationVersionTextOnList:Point = new Point(listVersionLabel.x, listVersionLabel.y);
			
			var comboVersionLabel:Label = new Label("Label-SelectAuto_VersionComboBox");
			var textVersionFormatCombo:TextFormat =  new TextFormat(comboVersionLabel.font, comboVersionLabel.size, comboVersionLabel.color, comboVersionLabel.bold, comboVersionLabel.italic);
			var locationVersionTextOnCombo:Point = new Point(comboVersionLabel.x, comboVersionLabel.y);
			comboboxVersion = new Combobox("Box-SelectAuto_VersionComboBox", "Box-SelectAuto_VersionComboBoxScroll",
				"Box-SelectAuto_VersionComboBoxSelectSkin", "Box-SelectAuto_VersionComboBoxSlider", "Box-SelectAuto_VersionComboBoxListBackground",
				textVersionFormatList, listVersionLabel.embedFonts, locationVersionTextOnList, textVersionFormatCombo, comboVersionLabel.embedFonts, locationVersionTextOnCombo, comboVersionLabel.text);
			addChild(comboboxVersion);
			
			function updateNextList(e:Event):void{
				var urlget:String = urlXml.url;
				var loader:URLLoader = new URLLoader();
				var targetCombobox: int;
				loader.dataFormat = URLLoaderDataFormat.TEXT;
				loader.addEventListener(Event.COMPLETE, completeHandler);
				
				var requestOnServ:URLRequest = new URLRequest(urlget);
				requestOnServ.method = URLRequestMethod.POST;
				switch (e.target){
					case comboboxMark: targetCombobox = 1;
						comboboxYears.list.Data = new Vector.<String>();
						comboboxModel.list.Data = new Vector.<String>();
						comboboxVersion.list.Data = new Vector.<String>();
						requestOnServ.data = ""+urlXml.urlBrend+brendXml[comboboxMark.index].attributes()[0]+urlXml.urlEnd;
					break;
					case comboboxYears: targetCombobox = 2;
						comboboxModel.list.Data = new Vector.<String>();
						comboboxVersion.list.Data = new Vector.<String>();
						requestOnServ.data = ""+urlXml.urlBrend+brendXml[comboboxMark.index].attributes()[0]+urlXml.urlYear
						+yearsValue[comboboxYears.index]+urlXml.urlEnd;
					break;
					case comboboxModel: targetCombobox = 3;
						comboboxVersion.list.Data = new Vector.<String>();
						requestOnServ.data = ""+urlXml.urlBrend+brendXml[comboboxMark.index].attributes()[0]+urlXml.urlYear
						+yearsValue[comboboxYears.index]+urlXml.urlModel+modelValue[comboboxModel.index]+urlXml.urlEnd;
					break;
				}
				loader.load(requestOnServ);
				function completeHandler(e:Event):void {
					trace(e.target.data);
					var jsonTemp:Array = JSON.decode(e.target.data);
					jsonTemp.shift();
					var textTemp:Vector.<String> = new Vector.<String>;
					var valueTemp:Vector.<String> = new Vector.<String>;
					for (var i2:int = 0; i2 < jsonTemp.length; i2++) {
						textTemp[i2] = String(jsonTemp[i2].text);
						valueTemp[i2] = String(jsonTemp[i2].value);
					}
					switch (targetCombobox){
						case 1:	comboboxYears.list.Data = textTemp; yearsValue = valueTemp;break;
						case 2:	comboboxModel.list.Data = textTemp; modelValue = valueTemp;break;
						case 3:	comboboxVersion.list.Data = textTemp; versionValue = valueTemp;break;
					}
				}
			}
		}
		private function ButtonOver(e:MouseEvent):void{
			e.currentTarget.removeEventListener(MouseEvent.MOUSE_OVER, ButtonOver);
			e.currentTarget.src = e.currentTarget.defaultSrc+DecalNameOver;
			e.currentTarget.addEventListener(MouseEvent.MOUSE_OUT, ButtonOut);
		}
		private function ButtonOut(e:MouseEvent):void{
			e.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT, ButtonOut);
			e.currentTarget.src = e.currentTarget.defaultSrc;
			e.currentTarget.addEventListener(MouseEvent.MOUSE_OVER, ButtonOver);
		}
		private function ButtonDown(e:MouseEvent):void{
			e.currentTarget.removeEventListener(MouseEvent.MOUSE_DOWN, ButtonOver);
			e.currentTarget.src = e.currentTarget.defaultSrc+DecalNameDown;
			e.currentTarget.addEventListener(MouseEvent.MOUSE_UP, ButtonUp);
		}
		private function ButtonUp(e:MouseEvent):void{
			e.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, ButtonUp);
			e.currentTarget.src = e.currentTarget.defaultSrc+DecalNameOver;
			e.currentTarget.addEventListener(MouseEvent.MOUSE_OVER, ButtonDown);
		}
		private function boxSliderDown(e:MouseEvent):void{
			updateSliderBars(e.currentTarget as DecalDisplay);
		}
		private function SliderDown(e:MouseEvent):void{
			currentBoxSlider = e.currentTarget.parent as DecalDisplay;
			stage.addEventListener(MouseEvent.MOUSE_MOVE, SliderMove);
			stage.addEventListener(MouseEvent.MOUSE_UP, SliderUp);
		}
		private function SliderUp(e:MouseEvent):void{
			stage.removeEventListener(MouseEvent.MOUSE_MOVE, SliderMove);
			stage.removeEventListener(MouseEvent.MOUSE_UP, SliderUp);
		}
		private function SliderMove(e:MouseEvent):void{
			updateSliderBars(currentBoxSlider);
		}
		private function updateSliderBars(targetSlider:DecalDisplay):void{
			if (targetSlider.mouseX < 0) targetSlider.getChildAt(1).x = - targetSlider.getChildAt(1).width / 2
			else if (targetSlider.mouseX > targetSlider.getChildAt(0).width) 
				targetSlider.getChildAt(1).x =	targetSlider.getChildAt(0).width - targetSlider.getChildAt(1).width / 2
			else targetSlider.getChildAt(1).x = targetSlider.mouseX - targetSlider.getChildAt(1).width / 2;
			switch (targetSlider){
				case boxColorSelect: curHSB.h = 359 - 359 * (targetSlider.getChildAt(1).x + targetSlider.getChildAt(1).width)
					/ targetSlider.width; break;
				case boxSaturationSelect: curHSB.s = 100 - 100 * (targetSlider.getChildAt(1).x + targetSlider.getChildAt(1).width)
					/ targetSlider.width; break;
				case boxBrightnessSelect: curHSB.b = 100 - 100 * (targetSlider.getChildAt(1).x + targetSlider.getChildAt(1).width)
					/ targetSlider.width; break;
			}
			change_rcx1_hsb(curHSB, boxSaturationSelect.getChildAt(0) as Bitmap, 1);
			change_rcx1_hsb(curHSB, boxBrightnessSelect.getChildAt(0) as Bitmap, 2);
			saturationBorder.bitmapData.floodFill(0, 0, ColorHSB.hsb_to_rgb(new ColorHSB(curHSB.h, 50, curHSB.b))|0xFF000000);
			brightnessBorder.bitmapData.floodFill(0, 0, ColorHSB.hsb_to_rgb(new ColorHSB(curHSB.h, 50, 50))|0xFF000000);
			changeColorAuto();
		}
			
		private function change_rcx1_hsb(hsb:ColorHSB, BM:Bitmap, n:uint):void {
			if (n > 3) return;
			var d:uint = 0;
			var o:ColorHSB = new ColorHSB(hsb.h, hsb.s, hsb.b);
			var m:String = "";
			
			var widthBar:int = BM.width - 1;
			
			if (n == 0) { m = "h"; d = 360; o.s = 100; o.b = 100; }
			if (n == 1) { m = "s"; d = 100; }
			if (n == 2) { m = "b"; d = 100; }
			
			for (var x:int = 0; x < widthBar + 1; x++) {
				o[m] = (x / widthBar) * d;
				var ColorRGB:uint = ColorHSB.hsb_to_rgb(o);
				for (var y:int = 0; y < BM.height; y++) {
					BM.bitmapData.setPixel(widthBar - x, y, ColorRGB);
				}
			}
		}
		private function auto():void{
			var AutoLoader:Loader = new Loader();
			AutoLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, AutoLoaded);
			AutoLoader.load(new URLRequest('img/mazda.png'));
			
			function AutoLoaded (e:Event):void{
				AutoLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE, AutoLoaded);
				AutoSourceBMD = e.target.content.bitmapData;
				AutoBM = new Bitmap(AutoSourceBMD.clone());
				
				rectAuto = AutoSourceBMD.getColorBoundsRect(0xFFFFFFFF, 0x000000, false);
				rectAuto.width += rectAuto.x;
				rectAuto.height += rectAuto.y;

				boxAuto = new DecalDisplay("Box-SelectAuto_Auto");
				boxAuto.addChild(AutoBM);
				addChildAt(boxAuto,1);
			}
		}
		private function changeColorAuto():void{
			if (AutoSourceBMD != null) {
				var pixelValue:uint;
				var alpha:uint;
				var red:uint;
				var green:uint;
				var blue:uint;
				var newPixelValue:uint;
				var newColor:uint = ColorHSB.hsb_to_rgb(new ColorHSB(curHSB.h, curHSB.s, curHSB.b));
				var newColorRed:uint = newColor >> 16 & 0xFF;
				var newColorGreen:uint = newColor >> 8 & 0xFF;
				var newColorBlue:uint = newColor & 0xFF;
				
				AutoBM.bitmapData.lock();
				for (var i:uint = rectAuto.x; i < rectAuto.width; i++){
					for (var j:uint = rectAuto.y; j < rectAuto.height; j++){
						pixelValue = AutoSourceBMD.getPixel32(i, j);
						if (pixelValue != 0){
							alpha = pixelValue >> 24 & 0xFF;
							red = pixelValue >> 16 & 0xFF;
							green = pixelValue >> 8 & 0xFF;
							blue = pixelValue & 0xFF;
							
							red *= (newColorRed+100)/255/1.2;
							green *= (newColorGreen+100)/255/1.2;
							blue *= (newColorBlue+100)/255/1.2;
							if (red > 0xFF) red = 0xFF;
							if (green > 0xFF) green = 0xFF;
							if (blue > 0xFF) blue = 0xFF;
							
							newPixelValue = alpha << 24 | red << 16 | green << 8 | blue;
							AutoBM.bitmapData.setPixel32(i,j,newPixelValue);
						}
					}					
				}
				AutoBM.bitmapData.unlock();
			}
		}
	}
}